<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 1. What is Smarty?</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="getting.started.html" title="Part I. Getting Started">
<link rel="prev" href="getting.started.html" title="Part I. Getting Started">
<link rel="next" href="installation.html" title="Chapter 2. Installation">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Chapter 1. What is Smarty?</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="getting.started.html">Prev</a> </td>
<th width="60%" align="center">Part I. Getting Started</th>
<td width="20%" align="right"> <a accesskey="n" href="installation.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter" title="Chapter 1. What is Smarty?">
<div class="titlepage"><div><div><h2 class="title">
<a name="what.is.smarty"></a>Chapter 1. What is Smarty?</h2></div></div></div>
<p>
   Smarty is a template engine for PHP. More specifically, it facilitates a
   manageable way to separate application logic and content from its
   presentation. This is best described in a situation where the application
   programmer and the template designer play different roles, or in most
   cases are not the same person.
  </p>
<p>
   For example, let's say you are creating a web page that is displaying a
   newspaper article.
   </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
   The article <code class="literal">$headline</code>, <code class="literal">$tagline</code>,
   <code class="literal">$author</code> and <code class="literal">$body</code> are
   content elements, they contain no information about how they will be
   presented. They are <a class="link" href="api.assign.html" title="assign()">passed</a> into Smarty
   by the application.
   </p></li>
<li class="listitem"><p>Then the
   template designer edits the templates and uses a combination of
   HTML tags and <a class="link" href="language.basic.syntax.html" title="Chapter 3. Basic Syntax">template tags</a>
   to format the presentation of these
   <a class="link" href="language.syntax.variables.html" title="Variables">variables</a> with elements
   such as tables, div's, background colors, font sizes, style sheets, svg etc.
   </p></li>
<li class="listitem"><p>One day
   the programmer needs to change the way the article content is retrieved, ie a
   change in application logic. This change does not affect the template
   designer, the content will still arrive in the template exactly the same.
   </p></li>
<li class="listitem"><p>
   Likewise, if the template designer wants to completely redesign the
   templates, this would require no change to the application logic.
   </p></li>
<li class="listitem"><p>Therefore,
   the programmer can make changes to the application logic without the need
   to restructure templates, and the template designer can make changes to
   templates without breaking application logic.
  </p></li>
</ul></div>
<p>
   One design goal of Smarty is the separation of business logic and
   presentation logic.
   </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
   This means templates can certainly contain logic under
   the condition that it is for presentation only. Things such as
   <a class="link" href="language.function.include.html" title="{include}">including</a>
   other templates,
   <a class="link" href="language.function.cycle.html" title="{cycle}">alternating</a> table row colors,
   <a class="link" href="language.modifier.upper.html" title="upper">upper-casing</a> a variable,
   <a class="link" href="language.function.foreach.html" title="{foreach},{foreachelse}">looping</a>
   over an array of data and <a class="link" href="api.display.html" title="display()">displaying</a> it
   are  examples of  presentation logic.
   </p></li>
<li class="listitem"><p>
   This does not mean however that Smarty forces a separation of
   business and presentation logic. Smarty has no knowledge of which is which,
   so placing business logic in the template is your own doing.
    </p></li>
<li class="listitem"><p>Also, if you
   desire <span class="emphasis"><em>no</em></span> logic in your templates you certainly can
   do so by boiling the content down to text and variables only.
  </p></li>
</ul></div>
<p>
   <span class="bold"><strong>Some of Smarty's features:</strong></span>
  </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
     It is extremely fast.
    </p></li>
<li class="listitem"><p>
     It is efficient since the PHP parser does the dirty work.
    </p></li>
<li class="listitem"><p>
     No template parsing overhead, only compiles once.
    </p></li>
<li class="listitem"><p>
     It is smart about <a class="link" href="variable.compile.check.html" title="$compile_check">recompiling</a>
     only the template files that have changed.
    </p></li>
<li class="listitem"><p>
     You can easily create your own custom <a class="link" href="language.custom.functions.html" title="Chapter 8. Custom Functions">functions</a>
     and <a class="link" href="language.modifiers.html" title="Chapter 5. Variable Modifiers">variable modifiers</a>, so the
     template language is extremely extensible.
    </p></li>
<li class="listitem"><p>
     Configurable template
     <a class="link" href="variable.left.delimiter.html" title="$left_delimiter">{delimiter}</a> tag
      syntax, so you can use
     <code class="literal">{$foo}</code>, <code class="literal">{{$foo}}</code>,
     <code class="literal">&lt;!--{$foo}--&gt;</code>, etc.
    </p></li>
<li class="listitem"><p>
     The <a class="link" href="language.function.if.html" title="{if},{elseif},{else}">
     <code class="literal">{if}..{elseif}..{else}..{/if}</code></a>
     constructs are passed to the
     PHP parser, so the <code class="literal">{if...}</code> expression syntax can be as
     simple or as complex an evaluation as you like.
    </p></li>
<li class="listitem"><p>
     Allows unlimited nesting of <a class="link" href="language.function.section.html" title="{section},{sectionelse}">
     <code class="varname">sections</code></a>, <code class="varname">if's</code> etc.
    </p></li>
<li class="listitem"><p>
     Built-in <a class="link" href="caching.html" title="Chapter 15. Caching">caching</a> support
    </p></li>
<li class="listitem"><p>
     Arbitrary <a class="link" href="resources.html" title="Chapter 16. Resources">template</a> sources
    </p></li>
<li class="listitem"><p>
    <a class="link" href="advanced.features.template.inheritance.html" title="Template Inheritance">Template Inheritance</a>
     for easy management of template content.
    </p></li>
<li class="listitem"><p>
     <a class="link" href="plugins.html" title="Chapter 18. Extending Smarty With Plugins">Plugin</a> architecture
    </p></li>
</ul></div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="getting.started.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="getting.started.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="installation.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Part I. Getting Started </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Chapter 2. Installation</td>
</tr>
</table>
</div>
</body>
</html>
